/*
 * GeneralPropPane.java
 *
 * Created on January 27, 2002, 3:11 PM
 *
 * Modification Log:
 * 1.00   27th Jan 2002   Tanmay   Original version.
 *-----------------------------------------------------------------------------------------
 *       10th Sep 2003   Tanmay   Moved to SourceForge (http://classeditor.sourceforge.net)
 *-----------------------------------------------------------------------------------------
 */

package gui.attributes;

import classfile.*;
import classfile.attributes.ConstantValueAttribute;
import classfile.attributes.Attribute;

/**
 * Copyright (C) 2002-2003  Tanmay K. Mohapatra
 * <br>
 * @author 	Tanmay K. Mohapatra
 * @version     1.00, 27th January, 2002
 */
public class ConstantValueAttribPane extends javax.swing.JPanel implements AttribDisplay {

    private ConstantValueAttribute attribute;
    private ConstantPool constPool;
    private boolean bModifyMode;
    
    /** Creates new form ConstantValueAttribPane */
    public ConstantValueAttribPane(boolean bModifyMode) {
        this.bModifyMode = bModifyMode;
        
        initComponents();
        txtAttribConstVal.setEnabled(bModifyMode);
        btnModConstValue.setEnabled(bModifyMode);
    }

    private void setAttribConstType(String sType)
    {
        if(sType.equals("long")) cmbAttribConstType.setSelectedIndex(1);
        else if(sType.equals("float")) cmbAttribConstType.setSelectedIndex(2);
        else if(sType.equals("double")) cmbAttribConstType.setSelectedIndex(3);
        else if(sType.equals("int, short, char, byte, boolean")) cmbAttribConstType.setSelectedIndex(4);
        else if(sType.equals("java.lang.String")) cmbAttribConstType.setSelectedIndex(5);
    }

    public void setInput(Attribute attribute, ConstantPool constPool) {
        this.attribute = (ConstantValueAttribute)attribute;
        this.constPool = constPool;
        
        setAttribConstType(((ConstantValueAttribute)attribute).sConstType);
        txtAttribConstVal.setText(((ConstantValueAttribute)attribute).sConstValue);
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        cmbAttribConstType = new javax.swing.JComboBox(new String[] {"", "long", "float", "double", "int, short, char, byte, boolean", "java.lang.String"});
        jLabel2 = new javax.swing.JLabel();
        txtAttribConstVal = new javax.swing.JTextField();
        btnModConstValue = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Constant Type");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        add(jLabel1, gridBagConstraints);

        cmbAttribConstType.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        add(cmbAttribConstType, gridBagConstraints);

        jLabel2.setText("Constant Value");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        add(jLabel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        add(txtAttribConstVal, gridBagConstraints);

        btnModConstValue.setText("Modify");
        btnModConstValue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModConstValueActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        add(btnModConstValue, gridBagConstraints);

    }//GEN-END:initComponents

    private void btnModConstValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModConstValueActionPerformed
        attribute.setConstantValue(txtAttribConstVal.getText());
    }//GEN-LAST:event_btnModConstValueActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnModConstValue;
    private javax.swing.JComboBox cmbAttribConstType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtAttribConstVal;
    // End of variables declaration//GEN-END:variables

}
